<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>面向对象</title>
</head>
<body>
    <script>
        // 以前
        // function Person(name,age){
        //     this.name=name;
        //     this.age=age;
        // }    
        // Person.prototype.showName=function(){
        //     return this.name;
        // }
        // Person.prototype.showAge=function(){
        //     return this.age;
        // }
        // var p1 = new Person('abc',1010);
        // alert(p1.showAge())

        // 现在
        class Person{
            constructor(name='default',age=108){
                this.name=name;
                this.age=age
            }
            showName(){
                return this.name;
            }
            showAge(){
                return this.age;
            }
        }
        var p1 = new Person('hhh',101)
        var p2 = new Person('ppp',111)
        alert(p2.name)
        alert(p2.showAge())
        alert(p2.showName ==p1.showName)

        var p3 = new Person() //如果没有默认值
        alert(p3.showName())//underfined

    </script>
    
</body>
</html>